export const formatTime = (date: Date) => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();

  return (
    [year, month, day].map(formatNumber).join("/") +
    " " +
    [hour, minute, second].map(formatNumber).join(":")
  );
};

const formatNumber = (n: number) => {
  const s = n.toString();
  return s[1] ? s : "0" + s;
};

export const getFailNoteList = () => {
  return new Promise((resolve, reject) => {
    wx.getStorage({
      key: "failNoteList",
      success(res) {
        console.log(res.data);
        let data = JSON.parse(res.data);
        resolve(data);
      },
      fail(err) {
        console.log("失败",err);
        resolve([])
      }
    });
  });
};

export const setFailNoteList = (arr: []) => {
  let data = JSON.stringify(arr);
  wx.setStorage({
    key: "failNoteList",
    data: data,
  });
};

export const pushFailNoteList = async (params) => {
  const list = await getFailNoteList() || []

  console.log("lisst",list);
  
  if (typeof params === 'object'){
    list.push(params)
    // 去重操作
  }else if (Array.isArray(params)){
    list.push(...params)
  }
  console.log("没有走");
  
  setFailNoteList(list)
};
